﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Yipusoft.Common.Model;
using Yipusoft.Common.BLL;
using Yipusoft.SoldierArchives.BLL;
using Yipusoft.SoldierArchives.Model;

public partial class Police_TransferQureyResult : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request["where"] != null)
        {
            lblWhere.Text = Request["where"];
            ListPageContral1.SetFirstPage();
            BindTransfer(0);
        }
    }

    protected void ListPageContral1_PageSizeChange(int pageSize, int PageIndex)
    {
        BindTransfer(PageIndex);
    }

    protected void gvTransfer_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
    {
        string TID = gvTransfer.DataKeys[e.NewSelectedIndex].Values["TransferID"].ToString();
        string ID = gvTransfer.DataKeys[e.NewSelectedIndex].Values["SoldierID"].ToString();
        Response.Redirect("TransfeSoldier.aspx?ID=" + ID + "&TID=" + TID);
    }
    protected void gvTransfer_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Soldier soldier = new Soldier();
            string ppid = gvTransfer.DataKeys[e.Row.RowIndex].Values["SoldierID"].ToString();
            Yipusoft.SoldierArchives.Model.SoldierArchiveInfo info = soldier.GetSoldierInfoByID(ppid);
            if (info != null)
            {
                e.Row.Cells[1].Text = soldier.GetSoldierInfoByID(ppid).SoldierName;
            }
            Label ID1 = (Label)e.Row.FindControl("ID");

            ID1.Text = ((int)ListPageContral1.CurrentPageIndex * 20 + e.Row.RowIndex + 1).ToString();


            //当鼠标放上去的时候 先保存当前行的背景颜色 并给附一颜色 
            e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#F5F5F5',this.style.fontWeight='';");
            //当鼠标离开的时候 将背景颜色还原的以前的颜色 
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor,this.style.fontWeight='';");
            
            //查看
            ImageButton btnview = e.Row.FindControl("btnview") as ImageButton;
            string trid = gvTransfer.DataKeys[e.Row.RowIndex].Values["TransferID"].ToString();
            TranslateLogInfo loginfo = TranslateLogs.GetDetailByDID(new Guid(trid));
            if (loginfo != null)
            {



                btnview.PostBackUrl = "TranslateProcess/TanslateDetail.aspx?Fid=" + loginfo.FID;
            }
            else
            {
                btnview.Visible = false;
            }
        }

    }

    private void BindTransfer(int pageIndex)
    {
        int totalCount = TransferSoldier.GetTransfersCountByWhere(lblWhere.Text);
        ListPageContral1.ItemCount = totalCount;
        gvTransfer.DataSource = TransferSoldier.GetTransfersByWhere(lblWhere.Text, 20, pageIndex);
        gvTransfer.DataBind();
        //lblDC.Text = TransferSoldier.GetTransfersCountByWhere();
    }
}
